package ren.edu.apollo.listener;

import com.ctrip.framework.apollo.model.ConfigChange;
import com.ctrip.framework.apollo.model.ConfigChangeEvent;
import com.ctrip.framework.apollo.spring.annotation.ApolloConfigChangeListener;
import com.ctrip.framework.apollo.spring.annotation.EnableApolloConfig;
import org.springframework.context.annotation.Configuration;

/**
 * @PackageName: ren.edu.apollo.listener
 * @ClassName: RedisConfigListener
 * @Description:
 * @author: RZS
 * @date: 2021/7/17  22:42
 */
@Configuration
@EnableApolloConfig
public class ApolloConfigListener {

    @ApolloConfigChangeListener
    private void redisCacheHostConfigChange(ConfigChangeEvent changeEvent) {
        /**
         * 指定监听的key
         * changeEvent.isChanged("redis.cache.host")
         */
        if(changeEvent.isChanged("redis.cache.host")) {
            // 获取指定的key的值  changeEvent.getChange("redis.cache.host")
            System.out.println("redis.cache.host发生修改了");
            System.out.println("变化情况："+changeEvent.getChange("redis.cache.host"));
        }
    }
}
